#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
	int n = 0123; 
	int m = 123;
	printf("%o %o\n", n, m);
}



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int get_sum(int* a, int left, int right)
{
    int sum = 0;
    while (left < right)
    {
        sum += a[left];
        ++left;
    }
    return sum;
}


int main()
{
    int n = 0;
    scanf("%d", &n);
    int* arr = (int*)malloc(sizeof(int) * n);
    int neg[100000] = { 0 };
    memset(neg, -1, sizeof(neg));
    if (NULL == arr)
    {
        perror("malloc fail");
        exit(-1);
    }
    neg[0] = 0;
    int count = 1;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &arr[i]);
        if (arr[i] < 0)
        {
            neg[count++] = i;
        }
    }
    neg[count++] = n;
    //printf("%d %d\n", n, count);
    int max = get_sum(arr, 0, n);
    int i = 0;
    if (count - 2 == n)
    {
        while (i < n)
        {
            if (arr[i] > max)
            {
                max = arr[i];
            }
            ++i;
        }
    }
    else
    {
        i = 0;
        while (neg[i] != -1)
        {
            for (int j = i; j < count; ++j)
            {
                int tmp = get_sum(arr, neg[i] + 1, neg[j + 1]);
                if (max < tmp)
                {
                    max = tmp;
                }
            }
            ++i;
        }
    }
    //printf("%d\n", max);

    printf("%d\n", max);
    return 0;
}